package barbershop.com.service.impl;

import barbershop.com.entity.Admin;
import barbershop.com.entity.Cashier;
import barbershop.com.service.TokenService;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.springframework.stereotype.Service;

@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public String getCasToken(Cashier cashier) {
        String token="";
        token= JWT.create().withAudience(cashier.getCasName())// 将 姓名 保存到 token 里面
                .sign(Algorithm.HMAC256(cashier.getCasPwd()));// 以 password 作为 token 的密钥
        return token;
    }

    @Override
    public String getAdminToken(Admin admin) {
        String token = "";
        token = JWT.create().withAudience(admin.getaName())
                .sign(Algorithm.HMAC256(admin.getaPwd()));
        return token;
    }
}
